package com.koron.dynamic.redis;

import com.koron.dynamic.koronDataSource.KrDataSourceUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.connection.Message;
import org.springframework.data.redis.connection.MessageListener;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Component;

/**
 * @ClassName KrSubcribe
 * @description 订阅程序
 * @Author zhouj
 * @Date 2021/10/20 16:18
 */
@Slf4j
@Component
public class KrSubcribe implements MessageListener {

    @Autowired
    private StringRedisTemplate redisTemplate;

    @Override
    public void onMessage(Message message, byte[] pattern) {
        log.info("接收数据:{}", message.toString());
        log.info("订阅频道:{}", new String(message.getChannel()));
        KrDataSourceUtils.onMessage(message);
    }

}
